package com.briup.oagg.dataset.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.dataset.bean.ext.DatasetExt;
import com.briup.oagg.dataset.service.IDatasetService;
import com.briup.oagg.dataset.web.vm.DatasetAddVM;
import com.briup.oagg.dataset.web.vm.DatasetListVM;
import com.briup.oagg.dataset.web.vm.DatasetVM;
import com.briup.oagg.dataset.web.vm.DatasetUpdateVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 数据集信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "5.数据集管理")
@RestController
@RequestMapping("/dataset")
@Validated
public class DatasetController {
    @Autowired
    private IDatasetService datasetService;

    @ApiOperation(value = "新增数据集", notes = "输入盆地、区带、圈闭和油气藏、数据集和数据集描述信息。圈闭和油气藏信息和描述信息为非必填项，其他为必填。")
    @PostMapping
    public Response<String> addDataset(@RequestBody @Valid DatasetAddVM vm) {
        datasetService.addDataset(vm);
        return Response.success();
    }

    @ApiOperation(value = "修改数据集", notes = "只能修改数据集名称和数据集描述信息")
    @PutMapping
    public Response updateDataset(@RequestBody @Valid DatasetUpdateVM vm) {
        datasetService.updateDataset(vm);
        return Response.success();
    }

    @ApiOperation(value = "删除数据集", notes = "根据数据集编号删除数据集信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "datasetId", value = "数据集编号")
    })
    @DeleteMapping("/{datasetId}")
    public Response deleteById(@PathVariable @NotBlank(message = "数据集编号不能为空") String datasetId) {
        datasetService.deleteById(datasetId);
        return Response.success();
    }
    @ApiOperation("根据数据集编号查询数据集信息")
    @GetMapping("/{datasetId}")
    public Response<DatasetVM> findById(@PathVariable @NotBlank(message = "数据集编号不能为空") String datasetId) {
        DatasetVM vm = datasetService.findById(datasetId);
        return Response.success(vm);
    }

    @ApiOperation(value = "查询数据集总数")
    @GetMapping("/count")
    public Response<Integer> count() {
        int num = datasetService.countNum();
        return Response.success(num);
    }

    @ApiOperation(value = "分页多条件查询数据集", notes = "根据数据集名称模糊分页查询数据集信息，显示数据集信息和对应的地质信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页码",defaultValue = "1",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",defaultValue = "5",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "search", value = "关键字")
    })
    @GetMapping("/page")
    public Response<Page<DatasetListVM>> findByPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, String search) {
        Page<DatasetListVM> page = datasetService.findByPage(pageNum, pageSize, search);
        return Response.success(page);
    }

    @ApiOperation(value = "根据地质单元查询数据集", notes = "可以根据盆地编号，区带编号，圈闭编号和油气藏编号查询对应的数据集信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "basinId", value = "盆地编号"),
            @ApiImplicitParam(name = "zoneId", value = "区带编号"),
            @ApiImplicitParam(name = "trapId", value = "圈闭编号"),
            @ApiImplicitParam(name = "reservoirId", value = "油气藏编号")
    })
    @GetMapping("/all")
    public Response<List<DatasetVM>> findByCondition(String basinId, String zoneId, String trapId,  String reservoirId) {
        List<DatasetVM> list = datasetService.findByCondition(basinId, zoneId, trapId, reservoirId);
        return Response.success(list);
    }
}
